#include "wopTexture2D.h"

wopTexture2D::wopTexture2D()
{
}

wopTexture2D::~wopTexture2D()
{
}

GLuint wopTexture2D::getUnitID() const
{
	return mUnitID;
}

void wopTexture2D::bind()
{
	glBindTexture(GL_TEXTURE_2D, mUnitID);
}

void wopTexture2D::unbind()
{
	glBindTexture(GL_TEXTURE_2D, 0);
}

void wopTexture2D::upload(const int width, const int height, char* data, GLint internalFormat, GLenum format)
{
	glGenTextures( 1, &mUnitID );
	bind();

	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );

	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

	//if( MIPMAPPING )
	//{
	//	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );

	//	// create mipmaps
	//	gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
	//	GL_BGRA, GL_UNSIGNED_BYTE, data);
	//}
	//else
	//{
		
	// create the texture
	glTexImage2D( GL_TEXTURE_2D, 0, internalFormat, width, height,
			0, format, GL_UNSIGNED_BYTE, data);

	// unbind
	unbind();
}